﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace MyAMS.WebServer.ActionFilter
{
    class ActionFilterRecord
    {
        private readonly List<IActionFilterCriteria> criteria;
        public Type FilterType { get; private set; }

        public ActionFilterRecord(IEnumerable<IActionFilterCriteria> criteria, Type filterType)
        {
            this.criteria = new List<IActionFilterCriteria>(criteria);
            FilterType = filterType;
        }

        public bool Match(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            return criteria.Aggregate(true, (prev, f) => prev ? f.Match(controllerContext, actionDescriptor) : prev);
        }
    }
}
